<template>
  <div class="login">
    <div class="formLog">
      <h2>杰希报工平台</h2>
      <!--     <div style="height: 30px;"></div>-->
      <el-form :model="form">
        <el-form-item>
          <el-input
              v-model="form.userName"
              placeholder="请输入用户名"
          />
        </el-form-item>
        <el-form-item>
          <el-input
              v-model="form.password"
              placeholder="请输入密码"
              type="password"
              @keyup.enter.native="handleLogin"
          />
        </el-form-item>
        <el-form-item>
          <el-button style="width: 100%;font-size: 22px" size="medium" type="primary" @click="handleLogin">
            登 录
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { login } from '../../api/zhuye'
export default {
  data () {
    return {
      title: '',
      loading: false,
      login1: 1,
      val: '',
      form: {
        userName: '',
        password: ''
      },
      rules: {
        userName: [{ required: true, message: '用户名不能为空', trigger: 'blur' }],
        password: [{ required: true, message: '密码不能为空', trigger: 'blur' }]
      }
    }
  },
  created () {
    const user = window.localStorage.getItem('perUser')
    this.form.userName = user
  },
  methods: {
    // 登录
    handleLogin () {
      const { userName, password } = this.form
      if (!userName || !password) {
        this.$message.warning('请输入用户名或密码！');
        return
      }
      window.localStorage.setItem('perUser', userName)
      login({ ...this.form }).then(res => {
        if (res.code === 0) {
          window.sessionStorage.setItem('fuserId3', res.data.fuserId)
          window.sessionStorage.setItem('xuanpin', res.data.loginToken)
          this.$router.push({ path: '/' })
        } else {
          this.$message.error(res.message);
        }
      })
    },
  }
}
</script>
<style>
.formLog .el-input--medium .el-input__inner {
  height: 46px!important;
  line-height: 46px;
  font-size: 22px;
}
</style>
<style scoped lang="scss">
.login {
  padding: 0 20px;
  display: flex;
  justify-content: center;
  background-image: url("../../assets/svg/350.jpg");
  background-size: cover;
  background-position: center;
  height: 100%;
  .formLog {
    width: 500px;
    margin-top: 10%;
    .el-form {
      display: flex;
      flex-direction: column;
      .el-form-item {
        margin-bottom: 10px!important;
      }
    }
    h2 {
      font-size: 42px;
      color: #FFF;
      letter-spacing: 3px;
      text-align: center;
      margin: 30px 0;
    }
  }
}
</style>
